{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right"><a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="icon-plus"></i></a>
        <button type="button" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" onclick="confirm('{{ text_confirm }}') ? $('#form-menu').submit() : false;"><i class="icon-trash"></i></button>
      </div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="icon-warning"></i> {{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    {% if success %}
    <div class="alert alert-success alert-dismissible"><i class="icon-checkmark"></i> {{ success }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="icon-list"></i> {{ text_list }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ delete }}" method="post" enctype="multipart/form-data" id="form-menu">
          <div class="table-responsive">
            <table class="table table-hover">
              <thead>
                <tr>
                  <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                  <td class="text-left">{% if sort == 'name' %}
                    <a href="{{ sort_name }}" class="{{ order|lower }}">{{ column_name }}</a>
                    {% else %}
                    <a href="{{ sort_name }}">{{ column_name }}</a>
                    {% endif %}</td>
                  <td class="text-left">{% if sort == 'status' %}
                    <a href="{{ sort_status }}" class="{{ order|lower }}">{{ column_status }}</a>
                    {% else %}
                    <a href="{{ sort_status }}">{{ column_status }}</a>
                    {% endif %}</td>
                  <td class="text-right">{{ column_action }}</td>
                </tr>
              </thead>
              <tbody>
                {% if menus %}
                {% for menu in menus %}
                <tr>
                  <td class="text-center">{% if menu.menu_id in selected %}
                    <input type="checkbox" name="selected[]" value="{{ menu.menu_id }}" checked="checked" />
                    {% else %}
                    <input type="checkbox" name="selected[]" value="{{ menu.menu_id }}" />
                    {% endif %}</td>
                  <td class="text-left">{{ menu.name }}</td>
                  <td class="text-left">{{ menu.status }}</td>
                  <td class="text-right"><a href="{{ menu.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="icon-pencil"></i></a></td>
                </tr>
                {% endfor %}
                {% else %}
                <tr>
                  <td class="empty-result text-center" colspan="4">{{ text_no_results }}</td>
                </tr>
                {% endif %}
              </tbody>
            </table>
          </div>
        </form>
        <div class="row">
          <div class="col-sm-6 text-left">{{ pagination }}</div>
          <div class="col-sm-6 text-right">{{ results }}</div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="addNewModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">{{ text_add }}</h4>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="control-label">{{ entry_name }}</label>
            <input type="text" name="name" class="form-control" id="menu-name">
          </div>
          <input type="hidden" name="status" value="1" />
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ button_cancel }}</button>
        <button type="button" class="btn btn-primary btn-submit">{{ button_submit }}</button>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
$('#add-new').on('click', function (e) {
  e.preventDefault();

  $('#addNewModal').modal('show');

  $('#addNewModal').on('shown.bs.modal', function (e) {
    $('#menu-name').focus();
  });
});
$('#addNewModal .btn-submit').on('click', function (e) {
  var btn = this;  

  $.ajax({
    url: 'index.php?route=design/menu/new&user_token={{ user_token }}',   
    type: 'post',
    dataType: 'json',
    data: $('#addNewModal form').serialize(),
    beforeSend: function() {
      $(btn).button('loading');
    },
    complete: function() {
      $(btn).button('reset');
    },
    success: function(json) {
      $('.alert-dismissible').remove();

      if (json['error']) {
        $('#addNewModal .modal-body').prepend('<div class="alert alert-danger alert-dismissible"><i class="icon-warning"></i> ' + json['error']['message'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
      }

      if (json['redirect']) {
        location = json['redirect'];
      }
    },
    error: function(xhr, ajaxOptions, thrownError) {
      alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    }
  });
});
//--></script>
{{ footer }}